﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using SoftHelper.Model;
using SoftHelper.Tool;
using SoftHelper.View;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoftHelper.ViewModel
{
    public delegate void ChangeWindowHandler(Object content);
    public delegate void StepHandler(int num);
    public delegate void NextAndUp(int num);
    public class MainViewModel : ViewModelBase
    {
        private  int index;

        public  int Index 
        {
            get { return index; }
            set { index = value;RaisePropertyChanged("Index"); }
        }



        public static event NextAndUp NextAndUpEvent;
        public static event ChangeWindowHandler ChangeWindowEvent;
        public static event StepHandler StepEvent;
        private Object content;

        public Object Content
        {
            get { return content; }
            set { content =value; RaisePropertyChanged("Content"); }
        }


        private List<Object> contentList;

        public List<Object> ContentList
        {
            get { return contentList; }
            set { contentList = value; RaisePropertyChanged("ContentList"); }
        }


       
        private ObservableCollection<StepModel> stepList;

        public ObservableCollection<StepModel> StepList
        {
            get { return stepList; }
            set { stepList = value;RaisePropertyChanged("StepList");}
        }

        public MainViewModel()
        {
            StepList = new ObservableCollection<StepModel>() { new StepModel() { Step = "开始" }, new StepModel() {Step="选择项目" }, new StepModel() { Step = "设置源代码行数" }, new StepModel() { Step = "书写使用文档" }, new StepModel() { Step = "生成" }, };
            ContentList = new List<object>();
            init();
        }

        private void init()
        {
            Index = 0;


            StepEvent += MainViewModel_StepEvent;
            NextAndUpEvent += MainViewModel_NextAndUpEvent;
          
            ContentList.Add(new MainUserControl());
            ContentList.Add(new ChoseSoftDir());
            ContentList.Add(new UCSetValue());
            ContentList.Add(new UCWriteUserDoc());
            ContentList.Add(new UCDocGenerate());
            Content = ContentList[Index];

        }

        private void MainViewModel_NextAndUpEvent(int num)
        {
            if (num>0)
            {
                if (Index < ContentList.Count)
                {
                    Index++;
                    Content = ContentList[Index];
                }
            }
            else
            {
                if (Index > 0)
                {
                    Index--;
                    Content = ContentList[Index];
                }
            }
            
        }
            
        public static void ChangeFragment(int num)
        {
            NextAndUpEvent(num);
            StepEvent(num);
        }


        private void MainViewModel_StepEvent(int num)
        {
            Messenger.Default.Send<int>(num,"step");
        }

        
    }
}
